<template>
  <div class="pad_10">
    <el-form ref="queryRef" :inline="true" label-width="68px">
      <el-form-item>
        <el-button @click="handleQuery">保存</el-button>
        <el-button @click="Cancel">取消</el-button>
        <!-- <el-button :disabled="!route.query.id" @click="auditFun">审核</el-button> -->
      </el-form-item>
    </el-form>
    <el-divider />
    <SetUserSelect
      :key="keys"
      ref="setUserSelect"
      class="queryForm"
      :labelwidth="100"
      :isShowUserBtn="false"
      :buttonIsShow="false"
      :formData="bill"
      :queryParams="datas"
      @selChangeFun="changeFun"
    ></SetUserSelect>
  </div>
</template>
<script setup lang="ts">
import { ref, getCurrentInstance, watch } from "vue";
import { drugTypeList  } from "@/api/basicManagement/categoryMana";
import { adddrug, drugId, eitHdrug  } from "@/api/basicManagement/varietyMana";
import data from "./data";
import { useRoute } from "vue-router";
const { bill, datas } = data;
datas.value = {
  status: '1'
}
const { proxy } = getCurrentInstance();
let proxys: any = proxy;
const route: any = useRoute();
let keys = ref<any>("");
const { variety_mana_owner, variety_mana_status } = proxys.useDict(
  "variety_mana_owner",
  "variety_mana_status"
);
watch(variety_mana_owner, (newV, oldV) => {
  bill.value[3].selectData = variety_mana_owner;
  keys.value = new Date().getTime();
});
watch(variety_mana_status, (newV, oldV) => {
  bill.value[4].selectData = variety_mana_status;
  keys.value = new Date().getTime();
});
route.query.id &&
  drugId(route.query.id).then((res) => {
    res.data.status = "" + res.data.status;
    res.data.type = "" + res.data.type;
    res.data.setTime = res.data.createTime
    datas.value = res.data;
  });
const handleQuery = function (): void {
  proxys.$refs.setUserSelect.submitForm().then((valid) => {
    (!route.query.id ? adddrug : eitHdrug)(valid).then(() => {
      proxys.$modal.msgSuccess(`${route.query.id ? "修改" : "新增"}成功`);
      Cancel();
    });
  });
};
const changeFun = function (e: any): void {
  console.log(e);
};
const Cancel = () => {
  datas.value = {};
  const obj = { path: "/basicInformation/varietiesList" };
  proxys.$tab.closeOpenPage(obj);
};
const drugTypeListFun = () => {
  drugTypeList({
    pageNum: 1,
    pageSize: 100000,
  }).then((res:any) => {
    res.rows.length && res.rows.forEach((item) => {
      item.value = item.id
      item.label = item.name
    })
    bill.value[2].selectData = res.rows
    keys.value = new Date().getTime();
  })
}
drugTypeListFun()
</script>
<style scoped>
.pad_10 {
  padding: 10px;
}
.pad_10 .el-form--inline .el-form-item {
  margin: 0;
}
.el-divider--horizontal {
  margin: 10px 0;
}
</style>